import win32gui
import win32con
import win32clipboard as w
from splinter.browser import Browser
from time import sleep

def getText():
    """获取剪贴板文本"""
    w.OpenClipboard()
    d=w.GetClipboardData(win32con.CF_UNICODETEXT)
    w.CloseClipboard()
    return d

def setText(aString):
    """设置剪贴板文本"""
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_UNICODETEXT,aString)
    w.CloseClipboard()

def send_qq(to_who,msg):
    setText(msg)
    qq=win32gui.FindWindow(None,to_who)
    # win32gui.SendMessage(qq,258,22,2080193)
    win32gui.SendMessage(qq,770,0,0)

    # win32gui.SendMessage(qq,win32con.WM_SETTEXT,0,'QQ信息')
    win32gui.SendMessage(qq,win32con.WM_KEYDOWN,win32con.VK_RETURN,0)
    win32gui.SendMessage(qq,win32con.WM_KEYUP,win32con.VK_RETURN,0)




def search_ans(item):
    search_url="http://www.baidu.com";
    driver=Browser(driver_name='chrome',executable_path=r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts\chromedriver.exe')
    driver.driver.set_window_size(700,500)
    driver.visit(search_url)
    while True:
        driver.fill('wd',item)
        driver.find_by_value('百度一下').click()
        ele=driver.find_by_xpath('//*[@id="1"]/div/div[1]/div[2]/div[1]/div[1]/p/a')
        print(ele[0].text)
        return ele[0].text


    pass

to_who='木木的 Android手机'
item='被开头的成语'

search_ans(item);
msg='哈哈'
send_qq(to_who,msg)